package chpt07;

public class Account{
	private int balance;

	public Account(int balance) {
		super();
		this.balance = balance;
	}

	public synchronized int getBalance() {
		return balance;
	}

	public synchronized void setBalance(int balance) {
		this.balance = balance;
	}
	public synchronized void deposit(int money){
		setBalance(getBalance()+money);
		notify();//4-5
	}
	public synchronized void withdraw(int money){
		while(getBalance()<=0){
			try {
				wait();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		setBalance(getBalance()-money);
		notify();
		if(balance<0)//4-5
	        throw new IllegalStateException(balance+"");//4-5	
	}
}

